package br.unifor.ads.pjappfinanceiro.conexao;

import java.sql.Connection;
import java.sql.SQLException;

import com.jolbox.bonecp.BoneCP;
import com.jolbox.bonecp.BoneCPConfig;

public class ConnectionFactory {

	 private static BoneCP gpool = null;
     @SuppressWarnings("unused")
     private static final ConnectionFactory factory = new ConnectionFactory();
     
     private ConnectionFactory () {
             try {
                     BoneCPConfig config = new BoneCPConfig();
                     config.setJdbcUrl("jdbc:postgresql://localhost:5432/financeira");
                     config.setUser("postgres");
                     config.setPassword("123456");
                     config.setMinConnectionsPerPartition(3);
                     config.setMaxConnectionsPerPartition(50);
                     config.setPartitionCount(1);
                     
                     gpool  = new BoneCP(config);
             } catch (SQLException e) {
                     e.printStackTrace();
                     System.out.println();
             }
     }

     public static Connection getConnection() throws SQLException {
             Connection conn = gpool.getConnection();
             return conn;
     }
     
     public static void close(Connection conn) throws SQLException{
             conn.close();
     }
     
     public static void shutdown() throws SQLException{
             gpool.shutdown();
     }
	
	
}
